<template>
  <div class="examBody">
    <div class="topTitle">
      <span class="title">阅卷管理</span>
    </div>
    <div class="operate">
      <span>关键字:</span>
      <!-- 题库名称input -->
      <div class="key">
        <el-input
          v-model="params.key"
          class="w-50 m-2 keyInput"
          placeholder="请输入题库名称"
          clearable
        />
      </div>

      <!-- 搜索按钮11 -->
      <el-button
        type="primary"
        style="font-size: 12px; margin-left: 10px; width: 60px; height: 30px"
        @click="inquire"
        >搜索</el-button
      >
    </div>
    <div class="table">
      <!-- 表格 -->
      <el-table
        ref="multipleTableRef"
        :data="tableData"
        style="width: 100%"
        v-loading="loadings"
        :header-cell-style="{ backgroundColor: '#fafafa' }"
      >
        <el-table-column label="考试名称" width="300">
          <template #default="scope">
            {{ scope.row.title }}
          </template>
        </el-table-column>
        <el-table-column property="info" label="考试说明" />
        <el-table-column
          property="subjectnum"
          label="题量"
          show-overflow-tooltip
          ><template #default="scope">
            <span>{{ scope.row.subjectnum }}</span>
          </template></el-table-column
        >
        <el-table-column
          label="考试人数"
          property="studentcounts"
          show-overflow-tooltip
        />
        <el-table-column property="qorder" label="未判人数">
          <template #default="scope">
            <span style="color: red">{{ scope.row.incomplete }}</span>
          </template>
        </el-table-column>
        <el-table-column label="开放时间">
          <template #default="scope">
            <span>{{
              scope.row.begintime
                ? scope.row.begintime.substr(0, 16) +
                  "至" +
                  scope.row.endtime.substr(0, 16)
                : "不限"
            }}</span>
          </template></el-table-column
        >
        <el-table-column fixed="right" width="80" label="操作">
          <template #default="scope">
            <!-- 查看按钮 -->
            <el-button
              link
              type="primary"
              size="small"
              @click.prevent="lookRow(scope.row)"
              v-if="scope.row.incomplete === 0"
            >
              查看
            </el-button>
            <el-button
              link
              type="primary"
              size="small"
              @click.prevent="lookRow(scope.row)"
              v-if="scope.row.incomplete !== 0"
            >
              阅卷
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="demo-pagination-block">
        <el-pagination
          v-model:currentPage="params.page"
          v-model:page-size="params.psize"
          :page-sizes="[10, 20, 30, 100]"
          :small="small"
          :disabled="disabled"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="counts"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { inject, onMounted, reactive, toRefs } from "vue";
import { ElTable, ElMessage } from "element-plus";
import { getTestList } from "../../apis/exam/exam";
import { useRouter } from "vue-router";
// 路由跳转
const router = useRouter();
const data = reactive({
  small: false,
  background: false,
  disabled: false,
  counts: 0,
  loadings: false,
  //   请求列表数据
  params: {
    key: "",
    page: 1,
    psize: 10,
    isread: 1,
  },
  //   列表返回数据
  tableData: [],
});
const { params, small, background, counts, disabled, loadings, tableData } = toRefs(data);

const lookRow = (e: any) => {
  // console.log(e);
  router.push({name:'examstudent',query:{id:e.id,title:e.title}});
};
// 请求列表数据
const testList = async (params: any) => {
  data.loadings = true;
  const res: any = await getTestList(params).catch(() => {});
  if (res.errCode === 10000) {
    data.tableData = res.data.list;
    data.counts = res.data.counts;
  } else {
    ElMessage.error(res.errMsg);
  }
  data.loadings = false;
};

onMounted(() => {
  testList(data.params);
});
// 点击搜索
const inquire = () => {
  testList(params.value);
};
// 每页多少条内容改变
const handleSizeChange = (val: number) => {
  params.value.psize = val;
  testList(params.value);
};
// 页码内容改变
const handleCurrentChange = (val: number) => {
  params.value.page = val;
  testList(params.value);
};
</script>
<style scoped>
@import url("../../static/css/exam/exam.css");
</style>